<?php
class Client_m extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	//--get all clients--//
	function list_all_clients($per_page, $off_set){
		$query = 
				$this->db->select()
						 ->from("client")
						 ->limit($per_page, $off_set)
						 ->get();
		if($query->num_rows()>=0){
			return $query;
		
		}else{
			return FALSE;
		}
		
	}
	
	//--count clients--//
	function count_clients(){
		$query = 
				$this->db->select()
						 ->from("client")
						 ->get();
		$rowCount = $query->num_rows();
		if($rowCount >= 0){
			return $rowCount;
		}else{
			return 0;
		}
			
	}
	
	//--get client by name--//
	function count_client_by_name($client_name){
		$query = 
			$this->db->select()
					 ->from("client")
					 ->where("name", $client_name)
					 ->get();
		$rowCount = $query->num_rows();
		if($rowCount >= 0){
			return $rowCount;
		}else{
			return 0;
		}
	}
	
	//--add client--//
	function add_client($data){
		$query = 
			$this->db->insert("client", $data);
		return $query;	
	}
	
	//--get client details--//
	function get_client_details($client_id){
		$query = 
			 	$this->db->select()
			 			 ->from("client")
					     ->where("id", $client_id)
					     ->limit(1)
					     ->get();
		if($query -> num_rows() >0){
			return $query->row();
		}else{
			return FALSE;
		}
	}

	//--edit client details--//
	function edit_client($client_id, $data){
		$query = $this->db->update("client", $data, array("id"=>$client_id));
		return $query;
	}
	
	//--delete client--//
	function delete_client($id){
		$query = $this->db->delete('client', array('id' => $id));
		if($query){
			return $query;
		} else{
			return FALSE;
		}
		
	}
	
	//--delete multi clients--//
	function delete_multi_clients($list) {
        $this->db->where('id in ' . $list);
        $query = $this->db->delete('client');
        
        return $query;

    }
    
    //--add image--//
    function add_image($data){
    	$query = $this->db->insert("client_image", $data);
    	return $query;
    }
    
    //--count images--//
    function count_client_images(){
    	$query = 
    		$this->db->select()
    			 	 ->from('client_image')
    			 	 ->get();
    	$count = $query->num_rows();
    	if($count>=0){
    		return $count;
    	}else{
    		return FALSE;
    	}
    }
    //--list images--//
	function list_all_client_images($per_page, $off_set){
		$query = 
				$this->db->select()
						 ->from("client_image")
						 ->limit($per_page, $off_set)
						 ->get();
		if($query->num_rows()>=0){
			return $query;
		
		}else{
			return FALSE;
		}
		
	}
	//--get details of client image--//
	function get_client_image_details($id){
		$query = 
			 	$this->db->select()
			 			 ->from("client_image")
					     ->where("id", $id)
					     ->limit(1)
					     ->get();
		if($query -> num_rows() >0){
			return $query->row();
		}else{
			return FALSE;
		}
	}
	
	//--edit client image--//
	function edit_client_image($client_id, $data){
		$query = $this->db->update("client_image", $data, array("id"=>$client_id));
		return $query;
	}
	
	//--delete client image--//
	function delete_client_image($id){
		$query = $this->db->delete('client_image', array('id' => $id));
		if($query){
			return $query;
		} else{
			return FALSE;
		}
		
	}
	
	//--delete multi images--//
	function delete_multi_client_images($list) {
        $this->db->where('id in ' . $list);
        $query = $this->db->delete('client_image');
        return $query;
    }
}